//----------------------------------*-C++-*----------------------------------//
/*!
 * \file   MomentsIndex.cc
 * \author Jeremy Roberts
 * \date   Aug 30, 2011
 * \brief  MomentsIndex member definitions and explicit instantiations.
 * \note   Copyright (C) 2011 Jeremy Roberts. 
 */
//---------------------------------------------------------------------------//
// $Rev:: 141                                           $:Rev of last commit
// $Author:: j.alyn.roberts@gmail.com                   $:Author of last commit
// $Date:: 2011-09-14 19:28:23 +0000 (Wed, 14 Sep 2011) $:Date of last commit
//---------------------------------------------------------------------------//

#include "angle/MomentsIndex.hh"

namespace slabtran
{

// 3-d constructor.
template <class D>
MomentsIndex<D>::MomentsIndex(int legendre_order)
  : d_legendre_order(legendre_order),
    d_number_moments((legendre_order + 1) * (legendre_order + 1)),
    d_m_index(legendre_order + 1)
{
  Require(d_legendre_order + 1 == d_m_index.size());
  for (int l = 0; l <= d_legendre_order; l++)
  {
    int i = 0; // counter
    d_m_index[l].resize(2 * l + 1);
    for (int m = -l; m <= l; m++)
      d_m_index[l][i++] = m;
    Check(i == 2 * l + 1);
  }
}

// 2-d constructor.
template <>
MomentsIndex<_2D>::MomentsIndex(int legendre_order) :
  d_legendre_order(legendre_order),
  d_number_moments((legendre_order + 1) * (legendre_order + 2) / 2),
  d_m_index(legendre_order + 1)
{
  Require(d_legendre_order + 1 == d_m_index.size());
  d_m_index[0].resize(1); // do l = 0 separately
  d_m_index[0][0] = 0;
  for (int l = 1; l <= d_legendre_order; l++)
  {
    int i = 0; // counter
    d_m_index[l].resize(2 * l);
    for (int m = -l; m <= l; m++)
      if (m != 0) d_m_index[l][i++] = m;
    Check(i == 2 * l);
  }
}

// 1-d constructor.
template <>
MomentsIndex<_1D>::MomentsIndex(int legendre_order)
  : d_legendre_order(legendre_order),
    d_number_moments(legendre_order + 1),
    d_m_index(legendre_order + 1)
{
  Require(d_legendre_order + 1 == d_m_index.size());
  for (int l = 0; l <= d_legendre_order; l++)
  {
    d_m_index[l].resize(1); // \todo Generalize traits for D-templated vectors
    d_m_index[l][0] = 0;    // always zero
  }
}

// Instantiations.
template class MomentsIndex<_1D>;
template class MomentsIndex<_2D>;
template class MomentsIndex<_3D>;

} // end namespace slabtran

//---------------------------------------------------------------------------//
//              end of MomentsIndex.cc
//---------------------------------------------------------------------------//
